package org.example.struct.array2;

/**
 * @author liyishan
 * @date 2023/10/26 10:38
 * @apiNote
 */

public class Test00926MinFlipsMonoIncr {

    public static void main(String[] args) {
        String s = "10011111110010111011";
        int n = minFlipsMonoIncr(s);
        System.out.println(n);
    }
    public static int minFlipsMonoIncr(String s) {
        int n = s.length();
        int dp0 = 0, dp1 = 0;
        for(int i = 0; i < n; i++){
            char c= s.charAt(i);
            int dp0New = dp0, dp1New = Math.min(dp0,dp1);
            if(c=='1'){
                dp0New++;
            }else{
                dp1New++;
            }
            dp0 = dp0New;
            dp1 = dp1New;
        }
        return Math.min(dp0,dp1);
    }
}
